package com.java.yz.day14.SellTickets1;

public class Windows1 implements Runnable{
    int ticket =100;
    Object o = new Object();

    @Override
    public void run() {
        while (true) {
            //相当于加了一把锁
            synchronized (o) {
                if (ticket > 0) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "窗口正在卖 第" + (ticket--) + "张票");
                }
            }
        }
    }

}
